package com.chenhy.controller;

import com.chenhy.pojo.User;
import com.chenhy.security.LoginUser;
import com.chenhy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/personal")
public class PersonalController {

    @Autowired
    private UserService userService;

    @GetMapping("/information")
    public String toPersonalInformation(Model model){
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        User user = userService.queryUserById(loginUser.getId());
        model.addAttribute("user",user);
        return "personal/information";
    }

}
